import { stringify } from 'qs';
import request from '../utils/request';


export async function query(params) {
    return request.get('/api/shop/good/order', {params});
}

export async function queryMenus() {
    return request.get('/api/shop/category_menu');
}
export async function fetchItem(id) {
    return request.get(`/api/shop/good/order/${id}`);
}
export async function addItem(params) {
    if (params.photos) {
        params.photos = params.photos.map((item) => {
            return item.response.data.file;
        });
    }
    if ((params.category instanceof Array) && params.category.length > 0) {
        params.category = params.category[params.category.length - 1];
    }
    return request.post('/api/shop/good', params);
}

export async function express(params){
    return request.get(`/api/shop/good/order/express`, {params});
}

export async function changeItem(params) {
    if (params.photos) {
        params.photos = params.photos.map((item) => {
            return item.response.data.file;
        });
    }
    if ((params.category instanceof Array) && params.category.length > 0) {
        params.category = params.category[params.category.length - 1];
    }
    return request.put(`/api/shop/good/order/${params.id}`, params);
}

export async function cancelItem(params) {
    
    return request.put(`/api/shop/good/order/cancel/${params.id}`, params);
}

export async function sendItem(params) {
    return request.put(`/api/shop/good/order/send/${params.id}`,params);
}

export async function removeItem(params) {
    return request.delete(`/api/shop/good/order/${params.id}`);
}

